package com.example.qxfw.ldyj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.qxfw.common.entity.zy.BaseProduct;
import com.example.qxfw.ldyj.service.CpcxService;
import com.example.qxfw.mongodb.hy.entity.HyDocFile;
import com.example.qxfw.ybzz.mapper.BaseProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class CpcxServiceImpl implements CpcxService {
    @Autowired
    public BaseProductMapper baseProductMapper;

    @Qualifier("mongoSecondTemplate")
    @Autowired
    private MongoTemplate mongoTemplate;


    @Override
    public List<BaseProduct> getAllOfBaseProduct() {
        return baseProductMapper.selectList(null);
    }

    @Override
    public List<BaseProduct> selectByTypeAndTimePeriodOfBaseProduct(String producttype, Timestamp forecasttimeStart, Timestamp forecasttimeEnd) {
        return baseProductMapper.selectList(new LambdaQueryWrapper<BaseProduct>()
        .eq(StringUtils.isNotBlank(producttype), BaseProduct::getProducttype, producttype)
        .between(BaseProduct::getForecasttime, forecasttimeStart, forecasttimeEnd));
    }

    @Override
    public HyDocFile getById(String id) {
        return mongoTemplate.findById(id, HyDocFile.class);
    }
}
